# coding: utf-8
#!/usr/bin/python
import tkinter as tk
import json
import os
from tkinter import *
from tkinter import filedialog


def testSingleFile():
    file = filedialog.askopenfilename()
    loadJsonFile(file)


def selectBaseDir():
    Folderpath = filedialog.askdirectory(mustexist=True, )
    # 打印文件夹路径
    print('Folderpath:', Folderpath)
    if os.path.isdir(Folderpath + "/base"):
        print("base文件夹存在")
        return Folderpath
    else:
        print("ERROR:base文件夹不存在")


def loadFiles(dirpath):
    files = os.listdir(dirpath)
    for fi in files:
        fi_d = os.path.join(dirpath, fi)
        if os.path.isdir(fi_d):
            loadFiles(fi_d)
        else:
            loadJsonFile(os.path.join(dirpath, fi_d))


def loadJsonFile(path):
    with open(path, 'r', encoding='utf-8') as f:
        inJsonStrs = f.readlines()
    inJsonStr = ""
    for line in inJsonStrs:
        i = line.find("//")
        if i != -1:
            inJsonStr += line[0:i]
        else:
            inJsonStr += line

    # inJsonStr = inJsonStr.replace('\r', '')
    # inJsonStr = inJsonStr.replace('\n', '')
    # inJsonStr = inJsonStr.replace(' ', '')
    # inJsonStr = inJsonStr.replace('\000', '')
    text = json.loads(inJsonStr)

    print(text)


def test(root):
    print(root)


root = tk.Tk()
li = ['C', 'python', 'php', 'html', 'SQL', 'java']
listb = Listbox(root)
for item in li:  # 第一个小部件插入数据
    listb.insert(0, item)
listb.pack()

fileselect = Button(root, text="选择基准villain文件夹", command=testSingleFile)
fileselect.pack()
# 进入消息循环
root.mainloop()
